import { forwardRef, useImperativeHandle } from 'react'
import { Form, Input } from 'antd'

const FormConfig = forwardRef((props, ref) => {
    const [form] = Form.useForm()

    useImperativeHandle(ref, () => ({
        submit: () => form.validateFields(),
        reset: () => form.resetFields(),
    }))

    const onFinish = (values: any) => {
        console.log('Success:', values)
    }

    const onFinishFailed = (errorInfo: any) => {
        console.log('Failed:', errorInfo)
    }

    return (
        <Form
            form={form}
            name="basic"
            labelCol={{ span: 8 }}
            wrapperCol={{ span: 16 }}
            initialValues={{ remember: true }}
            onFinish={onFinish}
            onFinishFailed={onFinishFailed}
            autoComplete="off"
            layout="horizontal"
        >
            <Form.Item
                label="用户名"
                name="link"
                rules={[{ required: true, message: '请输入用户名' }]}
            >
                <Input />
            </Form.Item>

            <Form.Item
                label="suv"
                name="suv"
                rules={[{ required: true, message: '请输入suv' }]}
            >
                <Input />
            </Form.Item>
        </Form>
    )
})

export default FormConfig
